<?php

class UsuarioService extends BaseService {
	
	public function __construct() {
		$this->dao = new UsuarioDao(Config::getDateSourceName(), Config::$db_user, Config::$db_password);
	}
	
	public function findByName($name) {
		return $this->dao ? $this->dao->findByName($name) : NULL;
	}
	
	public function login($usuario) {
		return $this->dao ? $this->dao->login($usuario) : null; 
	}
	
	public function find($usuario) {
		if( $usuario->getNome() != null ) {
			if ( $usuario->getEmail() != null ) {
				return $this->dao ? $this->dao->query(array("nome" => $usuario->getNome(), "email" => $usuario->getEmail())) : NULL;
			} else {
				return $this->dao ? $this->dao->query(array("nome" => $usuario->getNome())) : NULL;
			}
		} else {
		if ( $usuario->getEmail() != null ) {
				return $this->dao ? $this->dao->query(array("email" => $usuario->getEmail())) : NULL;
			} else {
				return NULL;
			}
		}
	}
	
	public function listAlly() {
		$allyDao = new AliancaDao(Config::getDateSourceName(), Config::$db_user, Config::$db_password);
		return $allyDao ? $allyDao->findAll() : null;
	}
}
?>